package com.school.dcc.controller;

import com.school.dcc.pojo.Login;
import com.school.dcc.response.CommonResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Map;

/**
 * @author 又菜又爱玩
 * @version 1.0
 * @date 2022/1/9 17:27
 * @blog https://blog.csdn.net/biancheng4/article/details/121727982
 */
@Api(tags = "登录类")
@RestController
public class LoginController {


    @ApiOperation("用户登录")
    @PostMapping(value = "/login")
    public CommonResponse Login(@RequestBody Login login){
        System.out.println(login.getPassword());
        String token = login.getUsername();
        System.out.println(token);
        return CommonResponse.ok().data("data",token + "-accessToken");
    }

    @ApiOperation("用户信息")
    @PostMapping("/userInfo")
    public CommonResponse info(@RequestBody Map<String, Object> token){
        String str = String.valueOf(token.get("accessToken"));
        System.out.println(str);
        String tokenByRole = str.substring(0, str.indexOf('-'));
        ArrayList list = new ArrayList();
        list.add(tokenByRole);
        return CommonResponse.ok()
                .data("permissions",list)
                .data("avatar","https://img0.baidu.com/it/u=3623309039,2407011632&fm=26&fmt=auto");
    }


    @ApiOperation("用户退出")
    @GetMapping("/logout")
    public CommonResponse logout(){
        return CommonResponse.ok().data("token", "admin");
    }


    @ApiOperation("密钥")
    @PostMapping("/publicKey")
    public CommonResponse Key(){
        return CommonResponse.ok().data("mockServer", false)
                .data("publicKey", "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDBT2vr+dhZElF73FJ6xiP181txKWUSNLPQQlid6DUJhGAOZblluafIdLmnUyKE8mMHhT3R+Ib3ssZcJku6Hn72yHYj/qPkCGFv0eFo7G+GJfDIUeDyalBN0QsuiE/XzPHJBuJDfRArOiWvH0BXOv5kpeXSXM8yTt5Na1jAYSiQ/wIDAQAB");
    }



}
